<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>e4x.js unit tests</title>

<script type="text/javascript" src="e4x.js"></script>

<script type="text/javascript"
  src="../../../../javascript/closure/base.js"></script>
<script type="text/javascript">
  goog.require('goog.testing.jsunit');
</script>

<script type="text/javascript">
  var testVar;

  function setUp() {
  }

  function tearDown() {
  }

  function testSingleNode() {
    var xmlText = '<a>A</a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('a', xml.localName());
    assertEquals('A', xml.text());

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testSingleNodeWithAttributes() {
    var xmlText = '<a attr1="attr">A</a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('a', xml.localName());
    assertEquals('A', xml.text());
    assertEquals('attr', xml['@attr1']);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testChildText() {
    var xmlText = '<a><b>B</b><c>C</c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('B', xml.b);
    assertEquals('C', xml.c);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testMixedChildText() {
    var xmlText = '<a><b>B</b><c>C</c>A</a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('a', xml.localName());
    assertEquals('A', xml.text());
    assertEquals('B', xml.b);
    assertEquals('C', xml.c);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testNestedChildText() {
    var xmlText = '<a><b>B</b><c><d>D</d></c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('B', xml.b);
    assertEquals('D', xml.c.d);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testMixedNestedChildText() {
    var xmlText = '<a><b>B</b><c><d>D</d></c>A</a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('A', xml.text());
    assertEquals('B', xml.b);
    assertEquals('D', xml.c.d);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testChildArray() {
    var xmlText = '<a><b>B1</b><b>B2</b><c><d>D</d></c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('B1', xml.b[0]);
    assertEquals('B2', xml.b[1]);
    assertEquals('D', xml.c.d);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testAttributes() {
    var xmlText = '<a attr1="attr"><b>B1</b><b>B2</b><c><d>D</d></c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals("attr", xml['@attr1']);
    assertEquals('B1', xml.b[0]);
    assertEquals('B2', xml.b[1]);
    assertEquals('D', xml.c.d);

    var xmlFromObj = xml.toXml();
    assertEquals(xmlText, xmlFromObj);
  };

  function testDirectDecendant() {
    var xmlText = '<a attr1="attr"><b>B</b><c><d>D</d></c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('B', xml.descendants('b'));
  };

  function testDecendants() {
    var xmlText = '<a attr1="attr"><b>B</b><c><d>D</d></c></a>';
    var xml = new e4x.Xml(xmlText);

    assertEquals('D', xml.c.d);
    assertEquals('D', xml.descendants('d'));
  };

  function testRealParsing() {
    var xmlText = document.getElementById('xml-string').value;
    var xml = new e4x.Xml(xmlText);

    assertEquals('1962559', xml.descendants('bugId'));
  };
</script>
</head>
<body>
<textarea id="xml-string" style="display:none">
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <getBugByIdResponse
            soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <getBugByIdReturn xsi:type="ns1:BuganizerApiBugInfo"
                          xmlns:ns1="http://buganizer.corp.google.com/buganizerApi">
            <attachmentIds soapenc:arrayType="xsd:int[1]"
                           xsi:type="soapenc:Array"
                           xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                <attachmentIds xsi:type="xsd:int">491984</attachmentIds>
            </attachmentIds>
            <blockedByBugs soapenc:arrayType="xsd:int[0]"
                           xsi:type="soapenc:Array"
                           xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <blockingBugs soapenc:arrayType="xsd:int[0]"
                          xsi:type="soapenc:Array"
                          xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <bugId xsi:type="xsd:int">1962559</bugId>
            <ccs soapenc:arrayType="xsd:string[0]" xsi:type="soapenc:Array"
                 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <changelists soapenc:arrayType="xsd:string[0]"
                         xsi:type="soapenc:Array"
                         xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <componentId xsi:type="xsd:int">18917</componentId>
            <componentPath soapenc:arrayType="xsd:string[1]"
                           xsi:type="soapenc:Array"
                           xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                <componentPath xsi:type="xsd:string">{Trash}</componentPath>
            </componentPath>
            <createdDate xsi:type="xsd:dateTime">2009-07-06T17:17:01.000Z
            </createdDate>
            <customFieldBugValues
                    soapenc:arrayType="ns1:BuganizerApiCustomFieldBugValue[2]"
                    xsi:type="soapenc:Array"
                    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                <customFieldBugValues
                        xsi:type="ns1:BuganizerApiCustomFieldBugValue">
                    <customFieldId xsi:type="xsd:int">967</customFieldId>
                    <value xsi:type="xsd:string">DEFAULT</value>
                    <customFieldName xsi:type="xsd:string">my_custom_field
                    </customFieldName>
                    <customFieldType xsi:type="ns1:BuganizerApiCustomFieldType">
                        ENUM
                    </customFieldType>
                </customFieldBugValues>
                <customFieldBugValues
                        xsi:type="ns1:BuganizerApiCustomFieldBugValue">
                    <customFieldId xsi:type="xsd:int">1538</customFieldId>
                    <value xsi:type="xsd:string"></value>
                    <customFieldName xsi:type="xsd:string">test
                    </customFieldName>
                    <customFieldType xsi:type="ns1:BuganizerApiCustomFieldType">
                        ENUM
                    </customFieldType>
                </customFieldBugValues>
            </customFieldBugValues>
            <duplicateBugId xsi:type="xsd:int" xsi:nil="true"/>
            <foundInVersions soapenc:arrayType="xsd:string[0]"
                             xsi:type="soapenc:Array"
                             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <hotlists xsi:type="xsd:int" xsi:nil="true"/>
            <inProduction xsi:type="xsd:boolean">false</inProduction>
            <lastAction xsi:type="ns1:BuganizerApiBugAction">SAVE</lastAction>
            <modifiedDate xsi:type="xsd:dateTime">2009-07-06T18:06:27.000Z
            </modifiedDate>
            <notes soapenc:arrayType="xsd:string[3]" xsi:type="soapenc:Array"
                   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                <notes xsi:type="xsd:string">foo</notes>
                <notes xsi:type="xsd:string">Assigning to dahoward and
                    increasing priority.
                </notes>
                <notes xsi:type="xsd:string">test</notes>
            </notes>
            <numberOfNegativeVotes xsi:type="xsd:int">0</numberOfNegativeVotes>
            <numberOfPositiveVotes xsi:type="xsd:int">0</numberOfPositiveVotes>
            <owner xsi:type="xsd:string">wenboz</owner>
            <priority xsi:type="ns1:BuganizerApiBugPriority">P1</priority>
            <reporter xsi:type="xsd:string">wenboz</reporter>
            <resolution xsi:type="ns1:BuganizerApiBugResolution"
                        xsi:nil="true"/>
            <resolvedDate xsi:type="xsd:dateTime" xsi:nil="true"/>
            <severity xsi:type="ns1:BuganizerApiBugSeverity">S2</severity>
            <status xsi:type="ns1:BuganizerApiBugStatus">ASSIGNED</status>
            <summary xsi:type="xsd:string">Overview of bug</summary>
            <targetedToVersions soapenc:arrayType="xsd:string[0]"
                                xsi:type="soapenc:Array"
                                xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <type xsi:type="ns1:BuganizerApiBugType">BUG</type>
            <verifiedDate xsi:type="xsd:dateTime" xsi:nil="true"/>
            <verifiedInVersions soapenc:arrayType="xsd:string[0]"
                                xsi:type="soapenc:Array"
                                xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <verifier xsi:type="xsd:string" xsi:nil="true"/>
            <version xsi:type="xsd:int">2</version>
        </getBugByIdReturn>
    </getBugByIdResponse>
</soapenv:Body>
</soapenv:Envelope>
</textarea>
</body>
</html>
